package com.funcourse.demo.wechat.client.welet.accesstoken;

import com.funcourse.demo.wechat.conf.WeletConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class AccessTokenCaller {

  private static final String ADDRESS = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={APPID}&secret={APPSECRET}";
  @Autowired
  RestTemplate restTemplate;
  @Autowired
  WeletConfiguration weletConfiguration;

  public AccessTokenResponse callAccessToken() {
    return restTemplate.getForObject(ADDRESS, AccessTokenResponse.class,
        weletConfiguration.getAppId(), weletConfiguration.getAppSecret());
  }
}
